package com.qf.common.result;

import lombok.Data;

/**
 * @author Administrator
 */
@Data
public class ResponseResult<T> {
    private T data;
    private Integer code;
    private String message;

    private ResponseResult() {
    }

    public static <T> ResponseResult<T> success(T data) {
        return success(ResponseResultCode.SUCCESS, data);
    }

    public static <T> ResponseResult<T> success(ResponseResultCode resultCode, T data) {
        return common(resultCode, data);
    }


    public static <T> ResponseResult<T> error(ResponseResultCode resultCode, T errorData) {
        return common(resultCode, errorData);
    }

    public static <T> ResponseResult<T> error(ResponseResultCode resultCode) {
        return error(resultCode, null);
    }


    public static <T> ResponseResult<T> error() {
        return error(ResponseResultCode.SYS_ERROR);
    }

    private static <T> ResponseResult<T> common(ResponseResultCode resultCode, T data) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(resultCode.getCode());
        result.setMessage(resultCode.getMessage());
        result.setData(data);
        return result;
    }


}
